import { createIdAndKey } from '../utils/componetConfig.js'
import baseComponents, { getInput,getText } from './baseComponents.js'
import {deepClone, assign} from '../utils/index.js'

export let baseInfoCardBody = [
  getInput({
    __config__: {visible: true, showLabelChange: false, label: '项目名称', required: true, span: 8, labelPosition: "top"},placeholder: '自动获取用户所属项目的名称',disabled: true,
  }),
  getInput({
    __config__: {visible: true, showLabelChange: false, label: '所属项目公司', required: true, span: 8, labelPosition: "top"},placeholder: '自动获取用户所属项目的公司',disabled: true
  }),
  getInput({
    __config__: {visible: true, showLabelChange: false, label: '所属直属公司', required: true,trigger: 'change', span: 8, labelPosition: "top"},placeholder: '自动获取用户所属直属公司',disabled: true,
  }),
  getInput({
    __config__: {visible: true, showLabelChange: false, label: '项目状态', required: true, span: 8, labelPosition: "top"},placeholder: '自动获取项目状态',disabled: true
  }),
  getInput({
    __config__: {visible: true, showLabelChange: false, label: '项目类型', required: true, span: 8, labelPosition: "top"},placeholder: '自动获取项目类型',disabled: true
  })
]

let card = deepClone(baseComponents.find(t => t.__config__.name === '框体卡片'))

assign(card, {
  __config__: {
    label: '基本信息',
    group: 'item',
    showUpBtn: false,
    showDownBtn: false,
    showDeleteButton: false,
    canDraggable: false,
    children: {
      cardHeader: [
        getText({
          __config__: { showLabelChange: false, label: '卡片名称'},
          __slot__: {
            span: '基本信息'
          },
          style: {
            fontSize: '18px',
            lineHeight: '26px',
            fontWeight: 'bold'
          }
        })
      ],
      cardBody: baseInfoCardBody
    }
  }
})
card.__config__.startDragIndex = card.__config__.children.cardBody.length
card.__config__.checkMove = function(evt){
  // 获取拖动元素的索引和目标位置的索引
  const dragIndex = evt.draggedContext.index;
  const targetIndex = evt.relatedContext.index;
  // console.log(dragIndex, targetIndex);
  // console.log('targetIndex', targetIndex, 'startDragIndex',card.config.startDragIndex)
  let startDragIndex = card.__config__.startDragIndex
  if(startDragIndex !== undefined && targetIndex < startDragIndex-1){
    return false
  }
  if (targetIndex === startDragIndex-1) {
    return 1
  }
},
createIdAndKey(card)
card.__config__.children.cardBody.forEach(item => {
  createIdAndKey(item)
})
export default [
  card
]
